package com.cskaoyan.day16;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class DaTest {
    public static void main(String[] args) throws ParseException {
        System.out.println("请按照如下格式输入您的出生日期1970-01-01:");
        Scanner scanner = new Scanner(System.in);
        String birth = scanner.nextLine();
        int days = DayUtis.computeDay(birth.trim());
        System.out.println("您已经出生了" + days + "天");
    }
}

//模拟工具类
class DayUtis {
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    private DayUtis() {

    }

    public static int computeDay(String birtth) throws ParseException {
        Date parse = sdf.parse(birtth);
        long time = parse.getTime();
        long time1 = new Date().getTime();
        return (int) ((time1 - time) / 1000.0 / 3600 / 24);
    }
}
